package com.ophiux.wechatpay;


import org.apache.axis.utils.StringUtils;

import com.alibaba.fastjson.JSONObject;
import com.ophiux.wechatpay.util.AxisUtil;
import com.ophiux.wechatpay.util.HttpUtil;
import com.ophiux.wechatpay.util.PropertyUtil;

public class OphiuxWechatPayService  implements IOphiuxWechatPayPort {

	public String micropay(String data) {
		JSONObject jsonLocation = JSONObject.parseObject(data);
		//获取方法
//		String method = jsonLocation.getString("method");
		String method = "10";
		
		String result = "";
		if("1".equals(method)||StringUtils.isEmpty(method)) {
			result = AxisUtil.invoke(data, "micropay");
		}else if("2".equals(method)) {
			result = AxisUtil.invoke(data, "closeOrder");
		}else if("3".equals(method)) {
			result = AxisUtil.invoke(data, "refund");
		}else if("4".equals(method)) {
			result = AxisUtil.invoke(data, "queryOrderResult");
		}else if("5".equals(method)){
			result = AxisUtil.invoke(data, "queryOrder");
		}else if("6".equals(method)){
			result = AxisUtil.invoke(data, "smPay");
		}else if("7".equals(method)) {
			result = AxisUtil.invoke(data, "queryBillOrder");
		}else if("8".equals(method)) {
			result = AxisUtil.invoke(data, "queryThirdPartyBillOrder");
		}else if("9".equals(method)) {
			result = AxisUtil.invoke(data, "downloadBill");
		}else if("10".equals(method)) {
//			result = AxisUtil.invoke(data, "frushFacePay");
			result = HttpUtil.sendPost(PropertyUtil.getResWxValue("url"), "data="+data);
		}
		else {
			return "暂无该交易方式";
		}
		return result;
	}
	
	public String closeOrder(String data) {
		return AxisUtil.invoke(data, "closeOrder");
	}

	public String refund(String data) {
		return AxisUtil.invoke(data, "refund");
	}

	public String queryOrder(String data) {
		return  AxisUtil.invoke(data, "queryOrder");
	}

	public String queryOrderResult(String data) {
		return AxisUtil.invoke(data, "queryOrderResult");
	}

	public String smPay(String data) {
		return AxisUtil.invoke(data, "smPay");
	}

	public String queryBillOrder(String data) {
		return AxisUtil.invoke(data, "queryBillOrder");
	}

	public String queryThirdPartyBillOrder(String data) {
		return AxisUtil.invoke(data, "queryThirdPartyBillOrder");
	}

	public String downloadBill(String data) {
		return AxisUtil.invoke(data, "downloadBill");
	}

	public String frushFacePay(String data) {
		return HttpUtil.sendPost(PropertyUtil.getResWxValue("url"), "data="+data);
	}
}
